package com.smart.home.mapper;

import com.smart.home.annotation.autoFill;
import com.smart.home.entity.Homes;
import com.smart.home.enumeration.OperationType;
import com.smart.home.vo.HomesListVO;
import com.smart.home.vo.HomesVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HomeMapper {

    /**
     * 创建家庭
     * @param homeCreat
     */
    @autoFill(value = OperationType.INSERT)
    void CreateHome(Homes homeCreat);

    /**
     * 加入家庭
     * @param homes
     */
    @autoFill(value = OperationType.INSERT)
    void JoinHome(Homes homes);

    /**
     * 返回用户所有家庭信息
     * @param userId
     * @return
     */
    @Select("select id,name,timezone,created_at from smarthome.homes where owner_id = #{userId}")
    List<HomesVO> GetUerHome(Long userId);

    /**
     * 返回用户所有家庭列表
     * @param userId
     * @return
     */
    @Select("select id,name from smarthome.homes where owner_id = #{userId}")
    List<HomesListVO> GetUerHomeList(Long userId);

    /**
     * 通过家庭ID查询拥有者id
     * @param homeId
     */
    @Select("select owner_id from smarthome.homes where id = #{homeId} ")
    Long getIdByHomeName(Long homeId);


    /**
     * 删除家庭
     * @param homeId
     */
    @Delete("delete from smarthome.homes where id = #{homeId}")
    void DeleteHome(Long homeId);
}
